// 客户端

using JKFrame;
using Unity.Netcode;
using UnityEngine;

public partial class Player : NetworkBehaviour
{
    public Transform cameraLooakTarget;
    public Transform cameraFollowTarget;
    private void Client_OnNetworkSpawn()
    {
        if (IsOwner)
        {
            EventSystem.TypeEventTrigger(new InitLocalPlayerEvent { localPlayer = this });
            this.AddUpdate(LocalClientUpdate);
        }
    }

    private Vector3 lastInputDir = Vector3.zero;
    private void LocalClientUpdate()
    {
        if (currentState.Value == PlayerState.None) return;
        float h = Input.GetAxisRaw("Horizontal");
        float v = Input.GetAxisRaw("Vertical");
        Vector3 inputDir = new Vector3(h, 0, v);
        if (inputDir == Vector3.zero && lastInputDir == Vector3.zero) return;
        lastInputDir = inputDir;

        float cameraEulerAngleY = Camera.main.transform.eulerAngles.y;
        // 四元数和向量相乘：让这个向量按照四元数所表达的角度进行旋转后得到一个新的向量
        SendInputMoveDirServerRpc(Quaternion.Euler(0, cameraEulerAngleY, 0) * inputDir);
    }
}
